<script type="text/javascript">


$(document).ready(function() {
    var data = JSON.parse($(".s_temple_setting.view_activity_detial_settings").html());
    console.log(data);
    if(!data.allowcomment){
		$(".s_comment_entry").hide();
    }else{
    	 bindAjaxForm($("#s_a_v_comment_reply"),s_a_v_onSuccess,s_a_v_onError);
    }
    $(".s_v_a_autherhead").attr("src",data.author.head_image_path);
    $(".s_v_a_authername").html(data.author.name).attr("href",getHomeURL(data.author.uid));
    $(".s_a_v_comment_reply_aid").attr("value",data.data.aid);
    $(".s_a_v_head").html(data.data.subject);
    content = data.data.content.replace(/\n|\r\n/g, "<br>")
    $(".s_v_a_content").html(content);
    index = getIndex(content,"<br>",3);
    if(index>=content.length){
		$(".s_text_shower").hide();
    }else{
    	$(".s_text_shower").addClass("enabled");
    	s_short = content.substring(0,index).replace(/\n|\r\n/g, "<br>")+"......";
    	$(".s_v_a_content").attr("short",s_short).attr("all",content).html(s_short);
    }
    $(".s_v_a_time").html(data.data.date);
    if(!data.admin){
		$(".s_adminbar").hide();
     }else{
		$(".s_a_v_admin").attr("aid",data.data.aid);
     }
 	$.each(data.appendixes,function(index,object){
		$(".s_append_images").append($("<img class='ui tiny image zoomfiy'>").attr("src",object).zoomify());;
 	});
 	$.each(data.comments,function(index,object){
 		s_a_v_loadComment(object);
 	});
 	console.log($.cookie("s_a_d_can_back"));
	if($.cookie("s_a_d_can_back")=="true"){
		$(".s_d_back").attr("style","");
	}
});
function s_a_v_loadComment(data){
	var $tmp = $("#s_a_v_comment_temple").clone();
	$tmp.attr("cid",data.cid).attr("id","").attr("style","");
	if(data.target_cid==-1||!data.hasOwnProperty("replycard")){
		 $tmp.find(".s_a_v_reply_symbol").hide();
		 $tmp.find(".s_a_v_comment_reply").hide();
	}else{
		 $tmp.find(".s_a_v_comment_reply").attr("href",getHomeURL(data.replycard.uid)).html(data.replycard.name);
	}
	 $tmp.find(".s_a_v_comment_headImage").attr("src",data.authorcard.head_image_path);
	 $tmp.find(".s_a_v_comment_author").html(data.authorcard.name).attr("href",getHomeURL(data.authorcard.uid));
	 $tmp.find(".s_a_v_comment_date").html(data.date);
	 $tmp.find(".s_a_v_comment_content").html(data.content);
	 $tmp.find(".s_a_v_comment_id").attr("cid",data.cid);
	
 	if(data.hasOwnProperty("children")&&!$.isEmptyObject(data.children)){
 	 	var parent_cid = data.cid;
	 	$.each(data.children,function(index,dat){
	 		$tmp.find(".s_a_v_children").append(s_a_v_loadChildComment(dat,parent_cid).clone());
 	 	});
 	}else{
		$tmp.find(".s_a_v_children").remove();
 	 }
 	$(".s_a_v_root_comments").append($tmp.clone());
}

function s_a_v_loadChildComment(data,parent_cid){
	var $ctmp = $("#s_a_v_comment_temple").clone();
	 $ctmp.attr("cid",data.cid).attr("id","").attr("style","");
	 $ctmp.find(".s_a_v_children").remove();
	if(data.target_cid==-1||!data.hasOwnProperty("replycard")){
		 $ctmp.find(".s_a_v_reply_symbol").hide();
		 $ctmp.find(".s_a_v_comment_reply").hide();
	}else{
		 $ctmp.find(".s_a_v_comment_reply").attr("href",getHomeURL(data.replycard.uid)).html(data.replycard.name);
	}
	 $ctmp.find(".s_a_v_comment_headImage").attr("src",data.authorcard.head_image_path);
	 $ctmp.find(".s_a_v_comment_author").html(data.authorcard.name).attr("href",getHomeURL(data.authorcard.uid));
	 $ctmp.find(".s_a_v_comment_date").html(data.date);
	 $ctmp.find(".s_a_v_comment_content").html(data.content);
	 $ctmp.find(".s_a_v_comment_id").attr("cid",data.cid); 
	 $ctmp.find(".s_a_v_comment_id").attr("parent_cid",parent_cid);
	return  $ctmp;
}

function opActivity(a){
	if(a.attr("op")=="remove"){
		s_a_v_removeActivity(a.attr("aid"));
	}
}
var windowScrollTop;
function s_a_v_onSuccess(data){
	s_a_v_operatedone(data.code,data.message,data.data);
}
function s_a_v_onError(data){
	console.log(data);
	s_a_v_operatedone(-101,"服务器返回了未知的数据，请前往console查看");
}
function s_a_v_operatedone(id,message,data){
	updateScroll();
	if(data.op=="request"){
		mainPageLoad(data.url);
	}
	if(data.close!=true){
		$(".s_a_v_message").html(message);
		$(".s_a_v_modal").modal("show");
	}
	reloadScroll();
}
function updateScroll(){
	 windowScrollTop = $(window).scrollTop()
	}
function reloadScroll(){
	window.scroll(0, windowScrollTop);
}
	
function s_a_v_removeActivity(aid){
	ajaxRequest("op=removeActivity&aid="+aid,"index.php?mod=home&childmod=home&ajax=true&op=activity_operate",s_a_v_onSuccess,s_a_v_onError);
}
function s_a_v_removeComment(cid){
	ajaxRequest("op=removeComment&cid="+cid,"index.php?mod=home&childmod=home&ajax=true&op=activity_operate",s_a_v_onSuccess,s_a_v_onError);
}
function removeComment(e){
	var cid = e.attr("cid");
	s_a_v_removeComment(cid);
}

function toggle_content(to){
	if(!to.hasClass("enabled")){
		return;
	}
	if(to.hasClass("s_text_hidden")){
		to.removeClass("s_text_hidden").removeClass("s_text_showed");
		container = to.parent().parent().find(".ui.text.container").find(".s_v_a_content");
		container.html(container.attr("all"));
		to.html("收起");
	}else{
		to.removeClass("s_text_showed").addClass("s_text_hidden");
		container = to.parent().parent().find(".ui.text.container").find(".s_v_a_content");
		console.log(container);
		container.html(container.attr("short"));
		to.html("展开");
	}
}
function moveReply(e){
	e.parent().parent().parent().append($("#s_a_v_comment_reply"));
	$("#s_a_v_comment_reply").find(".s_a_v_comment_reply_cid").attr("value",e.attr("cid"));
	$("#s_a_v_comment_reply").find(".s_a_v_comment_reply_parent_cid").attr("value",e.attr("parent_cid"));
	$("#s_a_v_comment_reply").find(".s_text").attr("placeholder","回复:"+e.parent().parent().find(".s_a_v_comment_author").html());
}

</script>
<style>
</style>
<h3>动态详情</h3>
<div class="ui success message hidden" id="s_a_v_message"></div>
<div class="s_temple_setting view_activity_detial_settings"><?php print_json_setting("view_activity_detial");?></div>
<div class="ui button s_d_back" onClick="mainPageComeBack()" style="display: none;">返回列表</div>
<div class="stuactive form" id="activetemple" style="padding-top: 1cm">
	<div class="ui top attached block header inline">
		<img class="ui avatar image s_v_a_autherhead">
		<span>
			<a class="s_v_a_authername s_activity_name"></a>
		</span>
		<div class="ui simple dropdown item" id="s_v_a_admin" style="display: none">
			<i class="dropdown icon"></i>
			<div class="menu">
				<a class="item stuactive delete"> 删除 </a>
			</div>
		</div>
	</div>
	<div class="ui bottom attached segment">
		<div class="ui text container" style="padding-down: 0.4cm">
			<h2 class="ui header s_a_v_head">标题</h2>
			<div class="s_v_a_content"></div>
		</div>
		<div class="s_actionbar">
			<div class="s_inline s_v_a_time"></div>
			<div class="s_inline s_text_shower s_text_hidden s_right_float" onClick="toggle_content($(this))">展开</div>
		</div>
		<div class="s_actionbar s_adminbar ">
			<div class="s_inline">管理选项：</div>
			<div class="s_division"></div>
			<div class="s_inline s_a_v_admin" op="remove" onClick="opActivity($(this))">删除</div>
		</div>
		<hr />
		<div class="s_append_images ui images"></div>
		<div class="ui comments s_a_v_root_comments">
			<form class="s_a_v_reply s_simple_reply s_comment_entry" url="index.php?mod=home&childmod=home&ajax=true&op=replyactivity" id="s_a_v_comment_reply">
				<input type="hidden" class="s_a_v_comment_reply_cid" name="cid">
				<input type="hidden" class="s_a_v_comment_reply_parent_cid" name="parent_cid">
				<input type="hidden" class="s_a_v_comment_reply_aid" name="aid">
				<div class="ui action fluid input">
					<input class="s_text" type="text" name="content" placeholder="回复...">
					<button class="ui button submit" type="submit">确定</button>
				</div>
			</form>
		</div>
	</div>
	<div class="comment" id="s_a_v_comment_temple" style="display: none;">
		<a class="avatar">
			<img class="s_a_v_comment_headImage">
		</a>
		<div class="content">
			<a class="author s_a_v_comment_author"></a>
			<span class="s_a_v_reply_symbol"> 回复 </span>
			<a class="author s_a_v_comment_reply"> </a>
			<div class="metadata">
				<span class="date s_a_v_comment_date"></span>
			</div>
			<div class="text s_a_v_comment_content"></div>
			<div class="actions">
				<a class="reply s_a_v_comment_id s_comment_entry" onClick="moveReply($(this))">回复</a>
				<a class="reply s_a_v_comment_id s_comment_entry s_a_v_admin" onClick="removeComment($(this))">刪除</a>
			</div>
		</div>
		<div class="s_a_v_cf"></div>
		<div class="comments s_a_v_children"></div>
	</div>
</div>
<div class="ui modal s_a_v_modal">
	<div class="header">提示消息</div>
	<div class="content">
		<div class="description s_a_v_message"></div>
	</div>
	<div class="actions">
		<div class="ui button" onClick="$('.s_a_v_modal').modal('hide')">了解</div>
	</div>
</div>
